using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.TestDrivens;
using Pixysoft.Framework.Configurations.Core;
using System.IO;
using Pixysoft.Framework.Configurations.Controller;

namespace Pixysoft.Framework.Configurations.TestCases
{
    [TestDriven(TestDrivenType.UnitTest, "SerializeController")]
    class UnitTest_019_SerializeController
    {
    static IAssert assert = Assert.New(true);

        [TestStart]
        public static bool TestCaseStart()
        {

            return true;
        }

        [TestStop]
        public static void TestCaseStop()
        {
        }

        [TestStateSave]
        public static ITestDrivenDocument TestCaseStateSave()
        {
            return assert.Document;
        }

        [TestCase("Serialize")]
        public static void TestCase_000_Serialize()
        {
            

            string id = "NoebeConfiguration";
            string name = "name";

            ConfigurationSetting setting = new ConfigurationSetting(id, null);
            string nodename = "nodename";
            IConfigurationNode node1 = new ConfigurationNode(nodename);
            node1.Text = "text";
            node1.Property.Add("property1", "property1111");
            IConfigurationProperty property2 = node1.Property.Add("property2");

            string filename = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "Pixysoft.dll";
            string classname = "Pixysoft.ByteBuilder";
            node1.Property.Add(StringHelper.default_attribute_filename, filename);
            node1.Property.Add(StringHelper.default_attribute_classname, classname);
            setting.Node.Add(node1);

            IConfigurationNode node2 = new ConfigurationNode(nodename);
            setting.Nodes.Add(node2);


            assert.Write(ConfigurationController.Instance.Serialize(setting, false));

            assert.Write(ConfigurationController.Instance.Serialize(setting, true, true));

            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory);
            string savefilename = path + StringHelper.default_config_filename;
            ConfigurationController.Instance.Save(savefilename, setting, false, true);
            assert.IsTrue(File.Exists(savefilename));
            assert.Write(File.ReadAllText(savefilename));
        }
    }
}
